﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class FriendLinkList : YuanlinUserControl,
        IReplyConverter<FriendLinkReply, GetListOperation>
    {
        protected Repeater list;
        private EntityList friendLinks;

        private int categoryId = UrlManager.Instance.GetParameterValue<int>(YuanlinParameterName.CategoryId);

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            if (!Page.IsPostBack)
            {
                FriendLinkListRequest request = new FriendLinkListRequest();
                request.CategoryId = categoryId;
                request.Title = "";
                request.PageIndex = 0;
                request.PageSize = 10000;
                requestBinders.Add(RequestHelper.BuildGetFriendLinkListRequest(this, request));
            }
        }

        private void BindData()
        {
            if (list == null)
            {
                return;
            }
            list.DataSource = friendLinks;
            list.DataBind();
        }

        #region IReplyConverter<FriendLinkReply,GetListOperation> Members

        public void ConvertReply(FriendLinkReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                friendLinks = reply.EntityList;

                if (!Page.IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
